//
//  HWPersonalDataViewController.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/10/21.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWPersonalDataViewController.h"
#import "HWPersonalDataCell.h"
#import "HWpersonalIcoCell.h"
#import "HWAddressManagementController.h"
#import "HWAES128.h"
#import "HWModifyNiChenViewController.h"
#import "HWRealNameAuthenticationController.h"
#import "HWGuanLianEmailViewController.h"




#define    wholeProjectBlackFontColor  RGB(51,51,51)

@interface HWPersonalDataViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView  *lowerPartView;
@property(strong,nonatomic) NSMutableArray *leftMuArr;
@property(strong,nonatomic) NSMutableArray *rightMuArr;
@property(strong,nonatomic) NSString *faceStr;
@property(strong,nonatomic) UIImageView *icoImageView;
@property(strong,nonatomic) UIImage *cunchuImage;


@end

@implementation HWPersonalDataViewController


-(UITableView *)mainaTableVie {

    if  (_mainaTableVie == nil) {

        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        _mainaTableVie.backgroundColor = [UIColor whiteColor];
        _mainaTableVie.backgroundColor = RGB(247, 247, 247);
        
    }
    return   _mainaTableVie ;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addCommonAttributes];
    [self setupUI];
    
    
}

// 添加常用的属性
- (void)addCommonAttributes {
    
    
    self.leftMuArr = [[NSMutableArray alloc]init];
//    [self.leftMuArr addObject:@"头像"];
//
//    [self.leftMuArr addObject:@"账号"];
//    [self.leftMuArr addObject:@"昵称"];
//    [self.leftMuArr addObject:@"性别"];
//    [self.leftMuArr addObject:@"生日"];
//  //   [self.leftMuArr addObject:@"成就勋章"];
//     [self.leftMuArr addObject:@"邮箱"];
    
    [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"头像"]];
    
    [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"账号"]];
    [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"昵称"]];
    [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"性别"]];
    [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"生日"]];
  //   [self.leftMuArr addObject:@"成就勋章"];
     [self.leftMuArr addObject:[HWjianzhiduiObject keylocalization:@"邮箱"]];
    
    
    
    
    
    
    self.rightMuArr = [[NSMutableArray alloc]init];
    [self.rightMuArr addObject:@""];
    [self.rightMuArr addObject:@"s454525"];
    [self.rightMuArr addObject:@"好嗨哦"];
    [self.rightMuArr addObject:@"请选择"];
    
    [self.rightMuArr addObject:@""];
  //   [self.rightMuArr addObject:@""];
     [self.rightMuArr addObject:@""];
    
    
    
}


//设置UI
- (void)setupUI {
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"个人资料";
    self.navigationItem.title = [HWjianzhiduiObject keylocalization:@"个人资料"];
    
    [self.view addSubview:self.mainaTableVie];

    // 添加底部
    [self addLowerPartView];
    
  
    
    
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
      [self chaxungerenziliao];
    
    self.navigationController.navigationBarHidden = NO;
}




- (void)chaxungerenziliao {
    
          NSString *userID = [HWLocallyStoredData getLoginUserID];
          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
          NSString *signMD5 = [WMUtil md5HexDigest:sign];
          NSDictionary *parametes = @{
                                     @"ct" :  @"app",
                                     @"ac" : @"account_info",
                                     @"ios" : @"1",
                                     @"uid" :userID,
                                     @"t" :tStr,
                                     @"sign": signMD5
                                     };
    
    
         
     //    [MBProgressHUD show:@"正在绑定邮箱"];
         
         [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
             
           
             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
          //   [MBProgressHUD hideHUD];
             
             
             if ([codeStr intValue] == 1) {
               
           
              //   [MBProgressHUD  showSuccess:response[@"message"]];
                 //[self.navigationController popViewControllerAnimated:YES];
                 self.faceStr = response[@"data"][@"face"];
                self.rightMuArr = [[NSMutableArray alloc]init];
                [self.rightMuArr addObject:@""];
                [self.rightMuArr addObject:response[@"data"][@"user_name"]];
                [self.rightMuArr addObject:response[@"data"][@"pet_name"]];
                [self.rightMuArr addObject:response[@"data"][@"gender"]];
                 
               
                [self.rightMuArr addObject: [NSString stringWithFormat:@"%@",response[@"data"][@"birthday"]]];
             //    [self.rightMuArr addObject:@""];
                 
               //   [NSString stringWithFormat:@"%@",response[@"data"][@"email"]];
                 
                [self.rightMuArr addObject:[NSString stringWithFormat:@"%@",response[@"data"][@"email"]]];
                 
                 
                 [self.mainaTableVie reloadData];
                

             } else {
              
                  [MBProgressHUD  showSuccess:response[@"message"]];
                 
             }
             NSLog(@"%@",response);
             
             
         } failure:^(NSString *error) {

             [MBProgressHUD  showError:@"查询失败"];
             
            
         }];
    
    
    
}


// 添加低部UIview
- (void)addLowerPartView {
    
    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-44-CF_TabbarSafeBottomMargin-15, kScreenW, 44+CF_TabbarSafeBottomMargin)];
    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
    self.lowerPartView.backgroundColor = [UIColor whiteColor];
    self.lowerPartView.backgroundColor = RGB(247, 247, 247);
    [self.view addSubview:self.lowerPartView];
     NSString *tuichudenglu =   [HWjianzhiduiObject keylocalization:@"退出登录"];
    
    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(20, 0, kScreenW-40, 44) Title:tuichudenglu Image:nil Font:14 Color:RGB(51, 51, 51) Target:self Selector:@selector(buttonTap)];
    butt.backgroundColor = RGB(255, 255, 255);
    butt.layer.cornerRadius = 22;
    butt.layer.masksToBounds = YES;
    [self.lowerPartView addSubview:butt];
    

    
    
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    
    return  2;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        
          return self.leftMuArr.count;
         
    } else {
        
          return 1;
        
    }
    
  
    
}

 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        static NSString *cellID = @"cellID1";
        HWpersonalIcoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        
        if (!cell) {
            cell = [[HWpersonalIcoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        
        [cell.icoIamgeView sd_setImageWithURL:[NSURL URLWithString:self.faceStr] placeholderImage:nil];
        cell.nameLabel.text  = self.leftMuArr[indexPath.row];

        return  cell;
    }
    
  
      static NSString *cellID = @"cellID";

      HWPersonalDataCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
           
      if (!cell) {
             cell = [[HWPersonalDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
         
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        if (indexPath.section == 0) {
              cell.nameLabel.text  = self.leftMuArr[indexPath.row];
              cell.nametextField.text = self.rightMuArr[indexPath.row];
              cell.nametextField.userInteractionEnabled = NO;
              cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            
        }else {
              
              
//              cell.nameLabel.text  = @"收货地址";
//              cell.nametextField.text = @"地址管理";
            
            cell.nameLabel.text  =  [HWjianzhiduiObject keylocalization:@"收货地址"];
            cell.nametextField.text = [HWjianzhiduiObject keylocalization:@"地址管理"];
            
            
              cell.nametextField.userInteractionEnabled = NO;
              cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
              
        }
         
        
        return  cell;
         


 
    
    
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        return  64;
    }
    
    return  64;
    
}



- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
    
    return  6;
    
//    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 6)];
//    backview.backgroundColor = RGB(241, 242, 244);
//
//    return backview;
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
        UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 6)];
        backview.backgroundColor = RGB(241, 242, 244);
    
        return backview;
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    if (indexPath.section == 1) {
        
        HWAddressManagementController *add = [[HWAddressManagementController alloc]init];
        [self.navigationController pushViewController:add animated:YES];
        
    } else if (indexPath.section ==  0) {
        
        if (indexPath.row == 0) {
            
            [self setUPUserImage];
                  
            
        }else if (indexPath.row == 1) {
            
            
        } else if (indexPath.row == 2) {
         
            HWModifyNiChenViewController *hwModel   = [[HWModifyNiChenViewController alloc]init];
            [self.navigationController pushViewController:hwModel animated:YES];
            
            
        } else if (indexPath.row == 3) {
            [self xiugaixingbie];
            
        } else if (indexPath.row == 4) {
            
            NSLog(@"生日");
            
            
               if ([self.rightMuArr[indexPath.row] isEqualToString:@""]) {
                      
                      HWRealNameAuthenticationController *authentication = [[HWRealNameAuthenticationController alloc]init];
                      [self.navigationController pushViewController:authentication animated:YES];
                
                
                
                      
                  } else {
                      
                        [MBProgressHUD  showError:@"你已经实名认证，生日是不能修改"];
                      
                  }
                  
            
            
            
            
            
            
        } else if (indexPath.row == 5) {
            
                NSLog(@"邮箱");
            
            
            
            if ([self.rightMuArr[indexPath.row]  isEqualToString:@""]) {
                
                
                                   
                HWGuanLianEmailViewController *youxiang = [[HWGuanLianEmailViewController alloc]init];
                [self.navigationController pushViewController:youxiang animated:YES];
                       
                   
             } else {
                       
                  
                       
                       
                                     
                                     
            }
                     
            
        }
       
        
    }

    
    
    
}


#pragma mark -----------    修改头像
- (void)xiugaitouxiang {
    
    
    
    [self shangchutupianjiekou];
    
    
    return;
    
    
         NSString *Bete64 = [self encodeToBase64String:self.cunchuImage];
    
          NSString *userID = [HWLocallyStoredData getLoginUserID];
          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
          NSString *signMD5 = [WMUtil md5HexDigest:sign];
          
          NSDictionary *signDic = @{
                                    @"face" : Bete64
            
                                    };
          NSString *jsonStr = [self convertToJsonData:signDic];
          NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
    
    
    
    
          NSDictionary *parametes = @{
                                     @"ct" :  @"app",
                                     @"ac" : @"re_info",
                                     @"ios" : @"1",
                                     @"uid" :userID,
                                     @"t" :tStr,
                                     @"sign": signMD5,
                                      @"value" : encryStr
                                     };
    
    
    
    [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
        
                NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
              
                   
                   
                   if ([codeStr intValue] == 1) {
                       [MBProgressHUD hideHUD];
                 
                    //   [MBProgressHUD  showSuccess:response[@"message"]];
                       //[self.navigationController popViewControllerAnimated:YES];
                       
                       [self chaxungerenziliao];
                       
                       
                        [MBProgressHUD  showSuccess:response[@"message"]];
                 
          
                      

                   } else {
                    
                        [MBProgressHUD  showError:response[@"message"]];
                       
                   }
                   NSLog(@"%@",response);
                   
        
    } failure:^(NSString *error) {

        [MBProgressHUD  showError:@"查询失败"];
        
        
    } ];
    
    
    
    
         
        
    
}



// 上传头像图片接口
- (void)shangchutupianjiekou {
    
    
    
    
         AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
         //接收类型不一致请替换一致text/html或别的
         manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
                                                              @"text/html",
                                                              @"image/jpeg",
                                                              @"image/png",
                                                              @"application/octet-stream",
                                                              @"text/json",
                                                              nil];
    
        NSString *userID = [HWLocallyStoredData getLoginUserID];
    NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
    NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
    
    
    NSString *signMD5 = [WMUtil md5HexDigest:sign];
                   
    
    
     
    NSDictionary *dic = @{@"uid":[HWLocallyStoredData getLoginUserID],@"t":tStr,@"sign":signMD5,@"image":@"image"};
    
    
         //AppDelegate *myDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        // NSDictionary *dic = @{@"id":myDelegate.userId};
        manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
        NSString *url = [NSString stringWithFormat:@"%@?ct=app&ac=upload",[HWOCGlobalConst baseUrl]];
    
         NSURLSessionDataTask *task = [manager POST:url parameters:dic  headers:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
             NSData *imageDatas = UIImageJPEGRepresentation(self.cunchuImage,1.0f);;
             NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
             formatter.dateFormat = @"yyyyMMddHHmmss";
             NSString *str = [formatter stringFromDate:[NSDate date]];
             NSString *fileName = [NSString stringWithFormat:@"%@.png", str];
             //上传的参数(上传图片，以文件流的格式)
             [formData appendPartWithFileData:imageDatas
                                         name:@"image"
                                     fileName:fileName
                                     mimeType:@"image/jpeg"];
         } progress:^(NSProgress * _Nonnull uploadProgress) {
             //打印下上传进度
             NSLog(@"上传进度");
             NSLog(@"%@",uploadProgress);
         } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             //上传成功
             NSLog(@"上传成功");
             NSLog(@"%@",responseObject);
            NSString * str  =[[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
             NSLog(@"上传成功");
             NSLog(@"上传成功");
             [self chuanURldaohoutai:str];
             
    
         } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
             //上传失败
             NSLog(@"上传失败");
         }];
    
        
    
    
    
    
    
    
    
    
}


// 上传Url
- (void)chuanURldaohoutai:(NSString *)urlStr {
    
    
        NSString *Bete64 = [self encodeToBase64String:self.cunchuImage];
          
                NSString *userID = [HWLocallyStoredData getLoginUserID];
                NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
                NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
                NSString *signMD5 = [WMUtil md5HexDigest:sign];
                
                NSDictionary *signDic = @{
                                          @"face" :urlStr,
                  
                                          };
                NSString *jsonStr = [self convertToJsonData:signDic];
    
    
    
                NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
       
          
          
          
          
                NSDictionary *parametes = @{
                                           @"ct" :  @"app",
                                           @"ac" : @"re_info",
                                           @"ios" : @"1",
                                           @"uid" :userID,
                                           @"t" :tStr,
                                           @"sign": signMD5,
                                            @"value" : encryStr
                                           };
          
          
          
          [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
              
                      NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                    
                         
                         
                         if ([codeStr intValue] == 1) {
                             [MBProgressHUD hideHUD];
                       
                          //   [MBProgressHUD  showSuccess:response[@"message"]];
                             //[self.navigationController popViewControllerAnimated:YES];
                             
                             [self chaxungerenziliao];
                             
                             
                              [MBProgressHUD  showSuccess:response[@"message"]];
                       
                
                            

                         } else {
                          
                              [MBProgressHUD  showError:response[@"message"]];
                             
                         }
                         NSLog(@"%@",response);
                         
              
          } failure:^(NSString *error) {

              [MBProgressHUD  showError:@"查询失败"];
              
              
          } ];
        
    
    
    
    
    
}







- (NSString*)encodeToBase64String:(UIImage*)image {

    return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    
    

}


-(NSString *)convertToJsonData:(NSDictionary *)dict {
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        NSLog(@"%@",error);
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
    
}







#pragma  mark  --------- 点击底部按钮一些操作

- (void)buttonTap {
    
    
    DLog(@"退出登录");
    
//    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
//    [defaults removeObjectForKey:@"userID"];
//    [defaults synchronize];
    
    
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要退出登录" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
         [HWLocallyStoredData setUserID:@""];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"userHeadImage"];
        [self.navigationController popViewControllerAnimated:YES];
        
        
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:okAction];
    [self presentViewController:alertController animated:YES completion:nil];
    
 
    
}




#pragma  mark  ------------  点击更换头像
- (void)setUPUserImage {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    NSString *paizhao = [HWjianzhiduiObject keylocalization:@"拍照"];
    
    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:paizhao style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //
        [self picturesImage];
    }];
    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
    
    
    
    NSString *xiancen = [HWjianzhiduiObject keylocalization:@"相册"];
    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:xiancen style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self photoAlbumImage];
    }];
    
    // KVC 改变颜色
    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];

    NSString *quxiao = [HWjianzhiduiObject keylocalization:@"取消"];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:quxiao style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
    }];
    // KVC 改变颜色
    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];

    [alert addAction:videoAction];
    [alert addAction:gifAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];

    
}

//点击拍照
- (void)picturesImage {
    
  
    

    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    
    if (result) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePicker animated:YES completion:nil];
        
        
    }else{
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
//        [alert show];
        
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    
        }];
        [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
        UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            
        }];
        // KVC 改变颜色
        [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
        [alert addAction:videoAction];
        [alert addAction:gifAction];
        [self presentViewController:alert animated:YES completion:nil];
//
      
        
    }

    
}


//点击相册
- (void)photoAlbumImage {

    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
    if (result) {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //                        [self presentModalViewController:imagePicker animated:YES];
        [self presentViewController:imagePicker animated:YES completion:nil];
    }else{
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
        [alert show];
    }
    
    
}


#pragma  mark ---------  UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
     UIImage *userImage = [self fixOrientation:(UIImage *)info[UIImagePickerControllerEditedImage]];
    // UIImagePickerControllerOriginalImage
   
    // 图片缩放
   //  userImage = [self scaleImage:userImage toScale:0.3];
      userImage = [self scaleImage:userImage toScale:1];
    
    //    照片上传
    // [self upDateHeadIcon:userImage];
    //保存图片 保存到沙河
    //   [self saveImage:userImage name:@"touxiang"];
    
    // QrCodeableViewCell *qrCodCell = [tableView dequeueReusableCellWithIdentifier:qrCodID];
    
//    NSIndexPath *inde = [NSIndexPath indexPathForRow:0 inSection:0];
//    IconInformationCell *iconcell =   (IconInformationCell *)[self.informationTableview cellForRowAtIndexPath:inde];
//    iconcell.IconImageView.image = userImage;
    
    self.cunchuImage = userImage;
    
//    if ([self.panduanStr isEqualToString:@"1"]) {
//        self.zhengmianImageView.hidden = NO;
//          self.zhengmianImageView.image = userImage;
//    } else {
//
//        self.fanmianImageview.hidden = NO;
//        self.fanmianImageview.image = userImage;
//
//
//
//    }
//
    // 修改头像
    [self xiugaitouxiang];
    
    //往配图相册view里面添加图片
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
}

//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
//    //    修正照片方向(手机转90度方向拍照)
//    UIImage *userImage = [self fixOrientation:[editingInfo objectForKey:@"UIImagePickerControllerOriginalImage"]];
//
//    // 图片缩放
//    userImage = [self scaleImage:userImage toScale:0.3];
//
//    //    照片上传
//   // [self upDateHeadIcon:userImage];
//    //保存图片 保存到沙河
//  //   [self saveImage:userImage name:@"touxiang"];
//
//    //往配图相册view里面添加图片
//    [picker dismissViewControllerAnimated:YES completion:nil];
//}


//修正照片方向(手机转90度方向拍照)
- (UIImage *)fixOrientation:(UIImage *)aImage {
    
    // No-op if the orientation is already correct
    if (aImage.imageOrientation == UIImageOrientationUp)
        return aImage;
    
    // We need to calculate the proper transformation to make the image upright.
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationDown:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformRotate(transform, M_PI_2);
            break;
            
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
            transform = CGAffineTransformRotate(transform, -M_PI_2);
            break;
        default:
            break;
    }
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationUpMirrored:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
            
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
        default:
            break;
    }
    
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
                                             CGImageGetColorSpace(aImage.CGImage),
                                             CGImageGetBitmapInfo(aImage.CGImage));
    CGContextConcatCTM(ctx, transform);
    switch (aImage.imageOrientation) {
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            // Grr...
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
            break;
            
        default:
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
            break;
    }
    
    // And now we just create a new UIImage from the drawing context
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage *img = [UIImage imageWithCGImage:cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return img;
    
    
}

//缩放图片
- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
{
 UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSLog(@"%@",NSStringFromCGSize(scaledImage.size));
    return scaledImage;
}

//保存照片到沙盒路径(保存)
- (void)saveImage:(UIImage *)image name:(NSString *)iconName
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    //写入文件
    NSString *icomImage = iconName;
    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", icomImage]];
    // 保存文件的名称
    //    [[self getDataByImage:image] writeToFile:filePath atomically:YES];
    [UIImagePNGRepresentation(image) writeToFile: filePath  atomically:YES];
}

//上传图片
- (void)upDateHeadIcon:(UIImage *)photo
{
    if (photo == nil) {
        return;
    }
    
    
}




//
- (void)xiugaixingbie {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    NSString *nastr =  [HWjianzhiduiObject keylocalization:@"男"];
    
    
    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:nastr style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        
        [self xingbieChuanru:@"1"];
        
        
       
    }];
    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
    
    NSString *nv =  [HWjianzhiduiObject keylocalization:@"女"];
    
    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:nv style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
          [self xingbieChuanru:@"0"];
        
    }];
    
    // KVC 改变颜色
    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
    
    NSString *quxiaonv =  [HWjianzhiduiObject keylocalization:@"取消"];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:quxiaonv style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        
    }];
    // KVC 改变颜色
    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];

    [alert addAction:videoAction];
    [alert addAction:gifAction];
    [alert addAction:cancelAction];
    [self presentViewController:alert animated:YES completion:nil];

    
}






-(void)xingbieChuanru:(NSString *)chuaru {
    
    
         NSString *userID = [HWLocallyStoredData getLoginUserID];
          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
          NSString *signMD5 = [WMUtil md5HexDigest:sign];
          
          NSDictionary *signDic = @{
              @"gender" : chuaru
              
            
                                    };
          NSString *jsonStr = [self convertToJsonData:signDic];
          NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
    
    
    
    
          NSDictionary *parametes = @{
                                     @"ct" :  @"app",
                                     @"ac" : @"re_info",
                                     @"ios" : @"1",
                                     @"uid" :userID,
                                     @"t" :tStr,
                                     @"sign": signMD5,
                                      @"value" : encryStr,
                                     };
    
    
    
    
    
         
     //    [MBProgressHUD show:@"正在绑定邮箱"];
    
    
     [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
        
                NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                //   [MBProgressHUD hideHUD];
                   
                   
                   if ([codeStr intValue] == 1) {
                     
                 
                      [MBProgressHUD  showSuccess:response[@"message"]];
                       //[self.navigationController popViewControllerAnimated:YES];
                       
                    //   [self.navigationController popViewControllerAnimated:YES];
                       
                        [self chaxungerenziliao];
                 
          
                      

                   } else {
                    
                        [MBProgressHUD  showError:response[@"message"]];
                       
                   }
                   NSLog(@"%@",response);
                   
        
    } failure:^(NSString *error) {

        [MBProgressHUD  showError:@"查询失败"];
    } ];
    
    
    
    
    
}




@end




#pragma mark ---------------  个人信息 以前的代码




//#import "HWPersonalDataViewController.h"
//#import "HWPersonalDataCell.h"
//#import "HWpersonalIcoCell.h"
//#import "HWAddressManagementController.h"
//#import "HWAES128.h"
//#import "HWModifyNiChenViewController.h"
//
//
//
//#define    wholeProjectBlackFontColor  RGB(51,51,51)
//
//@interface HWPersonalDataViewController ()<UITableViewDataSource,UITableViewDelegate>
//@property(strong,nonatomic) UITableView *mainaTableVie;
//@property(strong,nonatomic) UIView  *lowerPartView;
//@property(strong,nonatomic) NSMutableArray *leftMuArr;
//@property(strong,nonatomic) NSMutableArray *rightMuArr;
//@property(strong,nonatomic) NSString *faceStr;
//@property(strong,nonatomic) UIImageView *icoImageView;
//@property(strong,nonatomic) UIImage *cunchuImage;
//
//
//@end
//
//@implementation HWPersonalDataViewController
//
//
//-(UITableView *)mainaTableVie {
//
//    if  (_mainaTableVie == nil) {
//
//        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStylePlain];
//        _mainaTableVie.delegate = self;
//        _mainaTableVie.dataSource = self;
//        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
//
//        _mainaTableVie.backgroundColor = [UIColor whiteColor];
//        _mainaTableVie.backgroundColor = RGB(241, 242, 244);
//
//    }
//    return   _mainaTableVie ;
//
//}
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    // Do any additional setup after loading the view.
//    [self addCommonAttributes];
//    [self setupUI];
//
//
//}
//
//// 添加常用的属性
//- (void)addCommonAttributes {
//
//
//    self.leftMuArr = [[NSMutableArray alloc]init];
//    [self.leftMuArr addObject:@"头像"];
//    [self.leftMuArr addObject:@"账号"];
//    [self.leftMuArr addObject:@"昵称"];
//    [self.leftMuArr addObject:@"性别"];
//
//    self.rightMuArr = [[NSMutableArray alloc]init];
//    [self.rightMuArr addObject:@""];
//    [self.rightMuArr addObject:@"s454525"];
//    [self.rightMuArr addObject:@"好嗨哦"];
//    [self.rightMuArr addObject:@"请选择"];
//
//
//}
//
//
////设置UI
//- (void)setupUI {
//
//    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationItem.title = @"个人资料";
//    [self.view addSubview:self.mainaTableVie];
//
//    // 添加底部
//    [self addLowerPartView];
//
//
//
//
//}
//
//- (void)viewWillAppear:(BOOL)animated {
//
//    [super viewWillAppear:animated];
//
//      [self chaxungerenziliao];
//
//}
//
//
//
//
//- (void)chaxungerenziliao {
//
//          NSString *userID = [HWLocallyStoredData getLoginUserID];
//          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
//          NSString *signMD5 = [WMUtil md5HexDigest:sign];
//          NSDictionary *parametes = @{
//                                     @"ct" :  @"app",
//                                     @"ac" : @"account_info",
//                                     @"ios" : @"1",
//                                     @"uid" :userID,
//                                     @"t" :tStr,
//                                     @"sign": signMD5
//                                     };
//
//
//
//     //    [MBProgressHUD show:@"正在绑定邮箱"];
//
//         [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
//
//
//             NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//          //   [MBProgressHUD hideHUD];
//
//
//             if ([codeStr intValue] == 1) {
//
//
//              //   [MBProgressHUD  showSuccess:response[@"message"]];
//                 //[self.navigationController popViewControllerAnimated:YES];
//                 self.faceStr = response[@"data"][@"face"];
//                self.rightMuArr = [[NSMutableArray alloc]init];
//                [self.rightMuArr addObject:@""];
//                [self.rightMuArr addObject:response[@"data"][@"user_name"]];
//                [self.rightMuArr addObject:response[@"data"][@"pet_name"]];
//                [self.rightMuArr addObject:response[@"data"][@"gender"]];
//
//                 [self.mainaTableVie reloadData];
//
//
//             } else {
//
//                  [MBProgressHUD  showSuccess:response[@"message"]];
//
//             }
//             NSLog(@"%@",response);
//
//
//         } failure:^(NSString *error) {
//
//             [MBProgressHUD  showError:@"查询失败"];
//
//
//         }];
//
//
//
//}
//
//
//// 添加低部UIview
//- (void)addLowerPartView {
//
//    self.lowerPartView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenH-44-CF_TabbarSafeBottomMargin, kScreenW, 44+CF_TabbarSafeBottomMargin)];
//    // self.lowerPartView.backgroundColor = [UIColor yellowColor];
//    self.lowerPartView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.lowerPartView];
//
//    UIButton *butt  = [UIButton setButtonWithFrame:CGRectMake(0, 0, kScreenW, 44) Title:@"退出登录" Image:nil Font:14 Color:RGB(51, 51, 51) Target:self Selector:@selector(buttonTap)];
//    butt.backgroundColor = RGB(255, 255, 255);
//    [self.lowerPartView addSubview:butt];
//
//
//
//
//
//}
//
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//
//
//    return  2;
//
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//
//    if (section == 0) {
//
//          return self.leftMuArr.count;
//
//    } else {
//
//          return 1;
//
//    }
//
//
//
//}
//
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//
//
//    if (indexPath.section == 0 && indexPath.row == 0) {
//
//        static NSString *cellID = @"cellID1";
//        HWpersonalIcoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//
//        if (!cell) {
//            cell = [[HWpersonalIcoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
//        }
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.backgroundColor = [UIColor whiteColor];
//
//        [cell.icoIamgeView sd_setImageWithURL:[NSURL URLWithString:self.faceStr] placeholderImage:nil];
//
//     //   cell.textLabel.text = @"1";
//        return  cell;
//    }
//
//
//      static NSString *cellID = @"cellID";
//
//      HWPersonalDataCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//
//      if (!cell) {
//             cell = [[HWPersonalDataCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
//
//        }
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.backgroundColor = [UIColor whiteColor];
//        if (indexPath.section == 0) {
//              cell.nameLabel.text  = self.leftMuArr[indexPath.row];
//              cell.nametextField.text = self.rightMuArr[indexPath.row];
//              cell.nametextField.userInteractionEnabled = NO;
//              cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        }else {
//
//
//              cell.nameLabel.text  = @"收货地址";
//              cell.nametextField.text = @"地址管理";
//              cell.nametextField.userInteractionEnabled = NO;
//              cell.selectionStyle = UITableViewCellSelectionStyleNone;
//
//
//        }
//
//
//        return  cell;
//
//
//
//
//
//
//
//
//
//}
//
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//
//    if (indexPath.section == 0 && indexPath.row == 0) {
//        return  66;
//    }
//
//    return  40;
//
//}
//
//
//
//- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section {
//
//    return  6;
//
////    UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 6)];
////    backview.backgroundColor = RGB(241, 242, 244);
////
////    return backview;
//
//}
//
//
//- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//
//        UIView *backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 6)];
//        backview.backgroundColor = RGB(241, 242, 244);
//
//        return backview;
//
//
//}
//
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//
//
//    if (indexPath.section == 1) {
//
//        HWAddressManagementController *add = [[HWAddressManagementController alloc]init];
//        [self.navigationController pushViewController:add animated:YES];
//
//    } else if (indexPath.section ==  0) {
//
//        if (indexPath.row == 0) {
//
//            [self setUPUserImage];
//
//
//        }else if (indexPath.row == 1) {
//
//
//        } else if (indexPath.row == 2) {
//
//            HWModifyNiChenViewController *hwModel   = [[HWModifyNiChenViewController alloc]init];
//            [self.navigationController pushViewController:hwModel animated:YES];
//        } else if (indexPath.row == 3) {
//
//
//            [self xiugaixingbie];
//
//        }
//
//
//    }
//
//
//
//
//}
//
//
//#pragma mark -----------    修改头像
//- (void)xiugaitouxiang {
//
//
//
//         NSString *Bete64 = [self encodeToBase64String:self.cunchuImage];
//
//          NSString *userID = [HWLocallyStoredData getLoginUserID];
//          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
//          NSString *signMD5 = [WMUtil md5HexDigest:sign];
//
//          NSDictionary *signDic = @{
//                                    @"face" : Bete64
//
//                                    };
//          NSString *jsonStr = [self convertToJsonData:signDic];
//          NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
//
//
//
//
//          NSDictionary *parametes = @{
//                                     @"ct" :  @"app",
//                                     @"ac" : @"re_info",
//                                     @"ios" : @"1",
//                                     @"uid" :userID,
//                                     @"t" :tStr,
//                                     @"sign": signMD5,
//                                      @"value" : encryStr
//                                     };
//
//
//
//    [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
//
//                NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//
//
//
//                   if ([codeStr intValue] == 1) {
//                       [MBProgressHUD hideHUD];
//
//                    //   [MBProgressHUD  showSuccess:response[@"message"]];
//                       //[self.navigationController popViewControllerAnimated:YES];
//
//                       [self chaxungerenziliao];
//
//
//                        [MBProgressHUD  showSuccess:response[@"message"]];
//
//
//
//
//                   } else {
//
//                        [MBProgressHUD  showError:response[@"message"]];
//
//                   }
//                   NSLog(@"%@",response);
//
//
//    } failure:^(NSString *error) {
//
//        [MBProgressHUD  showError:@"查询失败"];
//
//
//    } ];
//
//
//
//
//
//
//
//}
//
//
//- (NSString*)encodeToBase64String:(UIImage*)image {
//
//    return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
//
//
//
//}
//
//
//-(NSString *)convertToJsonData:(NSDictionary *)dict {
//
//    NSError *error;
//
//    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
//
//    NSString *jsonString;
//
//    if (!jsonData) {
//        NSLog(@"%@",error);
//    }else{
//        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
//    }
//    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
//    NSRange range = {0,jsonString.length};
//
//    //去掉字符串中的空格
//    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
//    NSRange range2 = {0,mutStr.length};
//
//    //去掉字符串中的换行符
//    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
//
//    return mutStr;
//
//}
//
//
//
//
//
//
//
//#pragma  mark  --------- 点击底部按钮一些操作
//
//- (void)buttonTap {
//
//
//    DLog(@"退出登录");
//
////    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
////    [defaults removeObjectForKey:@"userID"];
////    [defaults synchronize];
//
//
//
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要退出登录" preferredStyle:UIAlertControllerStyleAlert];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//         [HWLocallyStoredData setUserID:@""];
//        [self.navigationController popViewControllerAnimated:YES];
//
//
//    }];
//
//    [alertController addAction:cancelAction];
//    [alertController addAction:okAction];
//    [self presentViewController:alertController animated:YES completion:nil];
//
//
//
//}
//
//
//
//
//#pragma  mark  ------------  点击更换头像
//- (void)setUPUserImage {
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        //
//        [self picturesImage];
//    }];
//    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//        [self photoAlbumImage];
//    }];
//
//    // KVC 改变颜色
//    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//
//    }];
//    // KVC 改变颜色
//    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    [alert addAction:videoAction];
//    [alert addAction:gifAction];
//    [alert addAction:cancelAction];
//    [self presentViewController:alert animated:YES completion:nil];
//
//
//}
//
////点击拍照
//- (void)picturesImage {
//
//
//
//
//    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
//
//    if (result) {
//        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//        imagePicker.delegate = self;
//        imagePicker.allowsEditing = YES;
//        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//        [self presentViewController:imagePicker animated:YES completion:nil];
//
//
//    }else{
////        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
////        [alert show];
//
//
//        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" preferredStyle:UIAlertControllerStyleAlert];
//        UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//        }];
//        [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//        UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//        }];
//        // KVC 改变颜色
//        [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//        [alert addAction:videoAction];
//        [alert addAction:gifAction];
//        [self presentViewController:alert animated:YES completion:nil];
////
//
//
//    }
//
//
//}
//
//
////点击相册
//- (void)photoAlbumImage {
//
//    BOOL result = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
//    if (result) {
//        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//        imagePicker.delegate = self;
//        imagePicker.allowsEditing = YES;
//        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//        //                        [self presentModalViewController:imagePicker animated:YES];
//        [self presentViewController:imagePicker animated:YES completion:nil];
//    }else{
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请在设置-->隐私-->相机，中开启本应用的相机访问权限！！" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"我知道了", nil];
//        [alert show];
//    }
//
//
//}
//
//
//#pragma  mark ---------  UIImagePickerControllerDelegate
//
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
//     UIImage *userImage = [self fixOrientation:(UIImage *)info[UIImagePickerControllerEditedImage]];
//    // UIImagePickerControllerOriginalImage
//
//    // 图片缩放
//    userImage = [self scaleImage:userImage toScale:0.3];
//
//    //    照片上传
//    // [self upDateHeadIcon:userImage];
//    //保存图片 保存到沙河
//    //   [self saveImage:userImage name:@"touxiang"];
//
//    // QrCodeableViewCell *qrCodCell = [tableView dequeueReusableCellWithIdentifier:qrCodID];
//
////    NSIndexPath *inde = [NSIndexPath indexPathForRow:0 inSection:0];
////    IconInformationCell *iconcell =   (IconInformationCell *)[self.informationTableview cellForRowAtIndexPath:inde];
////    iconcell.IconImageView.image = userImage;
//
//    self.cunchuImage = userImage;
//
////    if ([self.panduanStr isEqualToString:@"1"]) {
////        self.zhengmianImageView.hidden = NO;
////          self.zhengmianImageView.image = userImage;
////    } else {
////
////        self.fanmianImageview.hidden = NO;
////        self.fanmianImageview.image = userImage;
////
////
////
////    }
////
//    // 修改头像
//    [self xiugaitouxiang];
//
//    //往配图相册view里面添加图片
//    [picker dismissViewControllerAnimated:YES completion:nil];
//
//
//}
//
////- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
////    //    修正照片方向(手机转90度方向拍照)
////    UIImage *userImage = [self fixOrientation:[editingInfo objectForKey:@"UIImagePickerControllerOriginalImage"]];
////
////    // 图片缩放
////    userImage = [self scaleImage:userImage toScale:0.3];
////
////    //    照片上传
////   // [self upDateHeadIcon:userImage];
////    //保存图片 保存到沙河
////  //   [self saveImage:userImage name:@"touxiang"];
////
////    //往配图相册view里面添加图片
////    [picker dismissViewControllerAnimated:YES completion:nil];
////}
//
//
////修正照片方向(手机转90度方向拍照)
//- (UIImage *)fixOrientation:(UIImage *)aImage {
//
//    // No-op if the orientation is already correct
//    if (aImage.imageOrientation == UIImageOrientationUp)
//        return aImage;
//
//    // We need to calculate the proper transformation to make the image upright.
//    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
//    CGAffineTransform transform = CGAffineTransformIdentity;
//
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationDown:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
//            transform = CGAffineTransformRotate(transform, M_PI);
//            break;
//
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
//            transform = CGAffineTransformRotate(transform, M_PI_2);
//            break;
//
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
//            transform = CGAffineTransformRotate(transform, -M_PI_2);
//            break;
//        default:
//            break;
//    }
//
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationUpMirrored:
//        case UIImageOrientationDownMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRightMirrored:
//            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
//            transform = CGAffineTransformScale(transform, -1, 1);
//            break;
//        default:
//            break;
//    }
//
//    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
//                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
//                                             CGImageGetColorSpace(aImage.CGImage),
//                                             CGImageGetBitmapInfo(aImage.CGImage));
//    CGContextConcatCTM(ctx, transform);
//    switch (aImage.imageOrientation) {
//        case UIImageOrientationLeft:
//        case UIImageOrientationLeftMirrored:
//        case UIImageOrientationRight:
//        case UIImageOrientationRightMirrored:
//            // Grr...
//            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
//            break;
//
//        default:
//            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
//            break;
//    }
//
//    // And now we just create a new UIImage from the drawing context
//    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
//    UIImage *img = [UIImage imageWithCGImage:cgimg];
//    CGContextRelease(ctx);
//    CGImageRelease(cgimg);
//    return img;
//
//
//}
//
////缩放图片
//- (UIImage *)scaleImage:(UIImage *)image toScale:(float)scaleSize
//{
// UIGraphicsBeginImageContext(CGSizeMake(image.size.width*scaleSize,image.size.height*scaleSize));
//    [image drawInRect:CGRectMake(0, 0, image.size.width * scaleSize, image.size.height *scaleSize)];
//    UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    NSLog(@"%@",NSStringFromCGSize(scaledImage.size));
//    return scaledImage;
//}
//
////保存照片到沙盒路径(保存)
//- (void)saveImage:(UIImage *)image name:(NSString *)iconName
//{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//    //写入文件
//    NSString *icomImage = iconName;
//    NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png", icomImage]];
//    // 保存文件的名称
//    //    [[self getDataByImage:image] writeToFile:filePath atomically:YES];
//    [UIImagePNGRepresentation(image) writeToFile: filePath  atomically:YES];
//}
//
////上传图片
//- (void)upDateHeadIcon:(UIImage *)photo
//{
//    if (photo == nil) {
//        return;
//    }
//
//
//}
//
//
//
//
////
//- (void)xiugaixingbie {
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *videoAction = [UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//
//        [self xingbieChuanru:@"1"];
//
//
//
//    }];
//    [videoAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//    UIAlertAction *gifAction = [UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
//          [self xingbieChuanru:@"0"];
//
//    }];
//
//    // KVC 改变颜色
//    [gifAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//
//    }];
//    // KVC 改变颜色
//    [cancelAction setValue:wholeProjectBlackFontColor forKey:@"_titleTextColor"];
//
//    [alert addAction:videoAction];
//    [alert addAction:gifAction];
//    [alert addAction:cancelAction];
//    [self presentViewController:alert animated:YES completion:nil];
//
//
//}
//
//
//
//
//
//
//-(void)xingbieChuanru:(NSString *)chuaru {
//
//
//         NSString *userID = [HWLocallyStoredData getLoginUserID];
//          NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
//          NSString *sign = [NSString stringWithFormat:@"%@%@%@",userID,tStr,@"fsd213ewdsadqwe2121213edsad"];
//          NSString *signMD5 = [WMUtil md5HexDigest:sign];
//
//          NSDictionary *signDic = @{
//              @"gender" : chuaru
//
//
//                                    };
//          NSString *jsonStr = [self convertToJsonData:signDic];
//          NSString *encryStr = [HWAES128 AES128Encrypt:jsonStr key:@"mtetbpryjhdxmnhx"];
//
//
//
//
//          NSDictionary *parametes = @{
//                                     @"ct" :  @"app",
//                                     @"ac" : @"re_info",
//                                     @"ios" : @"1",
//                                     @"uid" :userID,
//                                     @"t" :tStr,
//                                     @"sign": signMD5,
//                                      @"value" : encryStr,
//                                     };
//
//
//
//
//
//
//     //    [MBProgressHUD show:@"正在绑定邮箱"];
//
//
//     [HWWebUtils doPostWithParameters:parametes progress:nil success:^(id response) {
//
//                NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
//                //   [MBProgressHUD hideHUD];
//
//
//                   if ([codeStr intValue] == 1) {
//
//
//                      [MBProgressHUD  showSuccess:response[@"message"]];
//                       //[self.navigationController popViewControllerAnimated:YES];
//
//                    //   [self.navigationController popViewControllerAnimated:YES];
//
//                        [self chaxungerenziliao];
//
//
//
//
//                   } else {
//
//                        [MBProgressHUD  showError:response[@"message"]];
//
//                   }
//                   NSLog(@"%@",response);
//
//
//    } failure:^(NSString *error) {
//
//        [MBProgressHUD  showError:@"查询失败"];
//    } ];
//
//
//
//
//
//}
//
//
//
//
//@end




